/************************************************
 * 文件描述: 程序主进程
 * 待完善:
 * 待优化:
 * 修改日期：2020.11.04
 * 修改内容：
 *   创建  HZH
 *************************************************/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QStackedWidget>
#include <QStandardPaths>
#include <QGSettings>
#include <xcb/xcb.h>

#include <QWidget>
#include <QStackedWidget>
#include <QGraphicsDropShadowEffect>
#include <QPalette>
#include <QApplication>
#include <QScreen>
#include <QLabel>
#include <QBoxLayout>
#include <QLineEdit>
#include <QPushButton>
//读取本地字体
#include <QFontDatabase>
//鼠标拖动事件
#include <QMouseEvent>
#include <QPoint>

#include <QPainter>
#include <QProxyStyle>

#include <QColor>
#include <QButtonGroup>
#include <QScrollArea>
#include <QFont>
#include "widget_parameter_class.h"
#include "messagePageStyle.h"
#include "tabmenu_button.h"
#include "contact_page.h"
#include "diysupport_page.h"
#include "menumodule.h"
#include "localInfo.h"
#include "messagePageStyle.h"
#include "intro_page_style.h"
#include "contact_page_style.h"
#include "guidance_page_style.h"
// TODO:需求未排期，暂不加入
//#include "web_browser.h"
#include "customui/customlabel.h"
#include "daemonipcdbus.h"
#include "navigatebar.h"
// SDK的widget控件
#include "kwidget.h"
#include "knavigationbar.h"
using namespace kdk;
QT_BEGIN_NAMESPACE
namespace Ui
{
    class MainWindow;
}
QT_END_NAMESPACE

//窗体长宽
const int SHAWINDOW_WIDTH = 960;
const int SHAWINDOW_HEIGHT = 640;
enum class PageNum : int
{
    MAINPAGINDEX = 0,
    MESSAGEPAGEINDEX,
    TEAMPAGEINDEX,
    DIYPAGEINDEX,
    WEBPAGEINDEX,
};

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void checkSingle();

    void changePageForTheme(const QString &str);
    void closeAboutWin();

    quint32 m_windowId = 0;
    double m_systemFontSize;

signals:
    void setFontSizeSignal();
    void setFontSignal();

protected:
    void keyPressEvent(QKeyEvent *event) override;
private slots:

    void gotoMainPage();
    void gotoMessagePage(); //点击“留言咨询”对应槽函数
    void gotoOnlinePage();  //点击“在线咨询”对应槽函数
    void gotoContactPage(); //点击“联系我们”对应槽函数
    void gotoDIYPage();     //点击“自助支持”对应槽函数

    void closeMainWidget(); //点击关闭事件

public slots:
    void pullUpWindow();

private:
    Ui::MainWindow *ui;

    int fd = -1;

    QStackedWidget *stackedWidget = nullptr;
    // getstting初始化、值获取、 设置getsetting值
    void initGsetting();
    void setThemeStyle();
    void getSysVersion();
    void changeTrans();
    void initFontSize();
    void initFont();
    void setQSSFontSize();
    void setQSSFont(const QString &currentFont);
    void changPage(const QString &curName);
    void changeTrans(double trans);
    void changeTitleFont(QFont font);

    QGSettings *m_pThemeStyle = nullptr;
    QGSettings *m_pGsettingControlTrans = nullptr; //控制面板透明度
    QGSettings *m_fontSize = nullptr;
    bool m_multiFunc = false;

    void initWidgetStyle();
    void initWidgetSize();
    void initWidgetBasicLayout();
    void initWidgetTabSection();
    void initWidgetLayout();

    QStackedWidget *m_pstackWidget = nullptr;

    QString m_currentTheme = "ukui-default";

    QWidget *m_title = nullptr;   //标题栏
    QWidget *m_showBox = nullptr; //窗体

    DaemonIpcDbus *m_daemonIpcDbus = nullptr;

    QPushButton *m_pwidgetCloseBtn = nullptr; //关闭窗口
    QPushButton *m_pwidgetMinBtn = nullptr;   //最小化窗口
    menuModule *m_pMenu = nullptr;            //三联按钮菜单按钮

    QScrollArea *m_scrollArea = nullptr;

    int m_currentPageIndex = static_cast<int>(PageNum::MESSAGEPAGEINDEX);

    IntroPageStyle *m_mainPage = nullptr;
    MessagePageStyle *m_messagePage = nullptr;
    ContactPageStyle *m_contactPage = nullptr;
    GuidancePageStyle *m_diySupportPage = nullptr;
    //    TODO:需求未排期，暂不上线
    //    WebBrowser *m_webPage = nullptr;
    LocalInfo *m_localInfo = nullptr;

    //透明度
    double m_tran = TRANSPARENCY_DEFAULT;

    KNavigationBar *m_pBar;
    QString m_titleText;
};
#endif // MAINWINDOW_H
